package com.example.gateway;

import com.moon.project.provider.RpcDemoService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.stereotype.Service;

@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
@EnableDubbo
@Service
public class MoonGatewayApplication {

    @DubboReference
    private RpcDemoService rpcDemoService;

    public static void main(String[] args) {

        // 创建一个ConfigurableApplicationContext对象，用于运行Spring Boot应用程序
        ConfigurableApplicationContext content = SpringApplication
                .run(MoonGatewayApplication.class, args);
        // 从ConfigurableApplicationContext对象中获取MoonGatewayApplication类的实例
        MoonGatewayApplication application = content
                .getBean(MoonGatewayApplication.class);
        String result1 = application.doSayHello("world-1...");
        String result2 = application.doSayHello2("world-2...");
        System.out.println(result1);
        System.out.println(result2);
    }

    public String doSayHello(String name) {
        return rpcDemoService.sayHello(name);
    }

    public String doSayHello2(String name) {
        return rpcDemoService.sayHello2(name);
    }

    /**
     * 编程式网关配置
     * 路由转发
     * @param builder
     * @return
     */
    //@Bean
    //public RouteLocator customRouteLocator(RouteLocatorBuilder builder) {
    //    return builder.routes()
    //            .route("toyupi", r -> r.path("/yupi")
    //                    .uri("http://yupi.icu/"))
    //            .build();
    //}

}
